Logic Question

I'm trying to modify an attribute of an object, which is of text type by creating a list. For all the links in the object, it will add the name of the links into the attribute as a list

ie. There are 5 links going out of object obj, so the attribute "Links" of obj would be:

link 1
link 2
link 3
link 4
link 5

However, I need to use a loop or recursive method to add a new line to the attribute, but in the end, I'll always end up with an empty line at the end, or an empty line at the beginning

obj."Link" = obj."Link" nameofLink "\n"

that will leave me with an empty line at the end or

obj."Link" = obj."Link" "\n" nameofLink

that will leave me with an empty line at the beginning of the list.

I'm sure there has to be some kind of algorithm to make a list and add only line breaks between the items on the list
phan423 - Tue Mar 06 14:51:20 EST 2012

Re: Logic Question
Mathias Mamsch - Wed Mar 07 08:45:49 EST 2012

The basic idea is to add the line break before adding a string, but first look if the target string is not empty:
 

string s = obj."Link" 
if (length s > 0) s = s "\n" nameofLink else s = nameOfLink
obj."Link" = s

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Logic Question
llandale - Wed Mar 07 17:04:51 EST 2012

The "length" check is good most of the time, but sometimes this is needed:

string EOL = ""
Buffer FinalResults = create()
for whatever my loop is
{  ThisResults = whatever I get from this loop
   FinalResults += EOL
   FinalResults += ThisResults
   EOL = "\n"    // get ready for next loop, if any
}
deal with FinalResults
delete(FinalResults)


As with the length check, you insert an EOL before an entry if there is already some results.

-Louie

You add an EOL before the line because at the point in time shen you want to add a line you can tell if you need an EOL prefix, but cannot tell if you are going to need an EOL suffix.

The notion of inserting an EOL before the current value is actually a fairly big paradigm shift. For similar reasons, MS-Word's notion of "Paragraph Keep-With-Next" is inferior to the non-existent notion of "Paragraph Keep-With-Previous": the Pragraphs of a heading will aways want to Keep-With-Previous and Headings will always not; while Keep-With-Next requires you to adjust the LAST paragraph of a section and sometimes turn it off for some Headings.

Basically, a paragraph is far more likely to know it's "first" in a sequence of similar paragraphs, then it is to know it's "last".